package com.yn.pet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yn.pet.bus.dao.AlarmRecordDao;
import com.yn.pet.bus.entity.AlarmRecord;
import com.yn.pet.bus.entity.GenFenceAlarm;
import com.yn.pet.service.AlarmRecordService;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * <p>
 * 警告记录信息表 服务实现类
 * </p>
 *
 * @author xuquanjun
 * @since 2025-07-17
 */
@Service
public class AlarmRecordServiceImpl extends ServiceImpl<AlarmRecordDao, AlarmRecord> implements AlarmRecordService {

    /**
     * 获取设备告警记录
     * @param deviceId 设备id
     * @param startTime 开始时间区间
     * @param endTime 结束时间区间
     * @return 告警记录数量
     */
    @Override
    public Long getCountByDeviceId(Long deviceId, Date startTime, Date endTime) {
        if(deviceId == null){
            return null;
        }
        LambdaQueryWrapper<AlarmRecord> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(AlarmRecord::getDeviceId, deviceId)
                .between(AlarmRecord::getCreateTime, startTime, endTime);
        return this.count(lambdaQuery);
    }


}
